<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Promise</title>
    <script type="text/javascript" src="./jquery.min.js"></script>
</head>

<body>
    <script>
        function getData(url, data = {}) {
            return new Promise((resolve, reject) => {
                $.ajax({
                    type: "GET",
                    url: url,
                    data: data,
                    success: function (res) {
                        resolve(res)
                    },
                    error: function (error) {
                        reject(error)
                    }
                })
            })
        }

        // 调用函数
        getData('data1.json')
            .then((data) => {
                const { id } = data;
                return getData('data2.json', { id })
            })
            .then((data) => {
                const { username } = data;
                return getData('data3.json', { username })
            })
            .then((data) => {
                console.log(data);
            })
    </script>
</body>

</html>